package com.lzm.ydpt.module.mall.activity;

import android.view.View;

import androidx.annotation.NonNull;

import com.byt.framlib.base.BaseActivity;
import com.byt.framlib.commonwidget.LoadingTip;
import com.byt.framlib.commonwidget.NormalTitleBar;
import com.byt.framlib.commonwidget.OnNoDoubleClickListener;
import com.byt.framlib.commonwidget.onclicktwo.AntiShake;
import com.byt.framlib.commonwidget.refresh.RefreshHeaderView;
import com.lzm.ydpt.Constants;
import com.lzm.ydpt.R;
import com.lzm.ydpt.entity.mall.ShopInfoBean;
import com.lzm.ydpt.mvp.contract.ShopInfoContract;
import com.lzm.ydpt.mvp.presenterimpl.ShopInfoPresenterImpl;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 商戶信息
 * */
public class ShopInfoActivity extends BaseActivity<ShopInfoPresenterImpl> implements ShopInfoContract.View {

    @BindView(R.id.ntb_shop_info)
    NormalTitleBar ntb_shop_info;
    @BindView(R.id.ltp_shop_info)
    LoadingTip ltp_shop_info;
    @BindView(R.id.srf_shop_info)
    SmartRefreshLayout srf_shop_info;


    private long info_id = 0L;
    private ShopInfoBean mShopInfoBean = null;

    @Override
    public int getLayoutId() {
        return R.layout.activity_shop_info;
    }



    @Override
    public ShopInfoPresenterImpl initPreData() {
        return new ShopInfoPresenterImpl(this);
    }

    @Override
    public void initView() {
        info_id = getIntent().getLongExtra(Constants.INP_SHOP_ID, 0L);
        initTitle();
        initRv();
        ltp_shop_info.setLoadingTip(LoadingTip.LoadStatus.loading);
        fetchShopInfoDetails();
    }

    private void initTitle() {
        ntb_shop_info.setBarLineVisibility(true);
        ntb_shop_info.setTitleMaxLength((int) getResources().getDimension(com.byt.framlib.R.dimen.x600));
        ntb_shop_info.setOnBackListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                finish();
            }
        });
    }

    private void initRv() {
        setRefreshLayout(srf_shop_info);
        srf_shop_info.setEnableLoadMore(false);
        srf_shop_info.setRefreshHeader(new RefreshHeaderView(this).getHeaderStyleStaffF4());
        srf_shop_info.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                fetchShopInfoDetails();
            }
        });
    }

    /**
     * 获取店铺详情
     */
    private void fetchShopInfoDetails() {
//        FormBodys.Builder formBodys = new FormBodys.Builder();
//        formBodys.add("store_id", info_id);
//        mPresenter.onShopInfo(formBodys.build());
    }


    @OnClick({})
    public void OnClick(View v) {
        if (AntiShake.check(v.getId())) {
            return;
        }
        switch (v.getId()) {
            case 0:
                break;
        }
    }

    @Override
    public void onShopInfo(ShopInfoBean xhxnInfoBean) {
        srf_shop_info.finishRefresh();
        if (xhxnInfoBean != null) {
            ltp_shop_info.setLoadingTip(LoadingTip.LoadStatus.finish);
            this.mShopInfoBean = xhxnInfoBean;
            initWidget();
        } else {
            ltp_shop_info.setLoadingTip(LoadingTip.LoadStatus.empty);
        }
    }

    /**
     * 控件数据
     */
    private void initWidget() {
//        ntb_shop_info.setTitleText(mShopInfoBean.getStore_name());
//        tv_store_open_time.setText("营业时间：" + mShopInfoBean.getBusiness_start_datetime() + " - " + mShopInfoBean.getBusiness_end_datetime());
    }


    @Override
    public void showMessage(String message, String method) {
        stopProgressDialog();
        showShortToast(message);
    }

    @Override
    public void showErrorView(String msg) {
        showErrorView(msg, ltp_shop_info);
        ltp_shop_info.setOnReloadListener(new LoadingTip.onReloadListener() {
            @Override
            public void reload(View view) {
                ltp_shop_info.setLoadingTip(LoadingTip.LoadStatus.loading);
                fetchShopInfoDetails();
            }
        });
    }
}